# -*- encoding:utf-8 -*-
'''
	moviedao.py
	======================
	@descript: 
	@copyright:chinasoft
	@author:gch
	@date: 2021-01-27 16:10
	@version:v1.0
'''
from entity.movieentity import MovieEntity
from tool.pymysqlutil import PyMysqlUtil

class Moviedao:
    def __init__(self):
        self.__pyMysqlUtil=PyMysqlUtil()
        pass
    def insertTable(self,movieEntity:MovieEntity):
        with self.__pyMysqlUtil as var_cursor:
            var_sql='INSERT INTO t_movieinfo(t_movieinfo.id,t_movieinfo.`filmname`,t_movieinfo.`var_url`,t_movieinfo.`filmdate`,t_movieinfo.`major`) values(NULL,%s,%s,%s,%s)'
            var_result=var_cursor.execute(var_sql,(movieEntity.filmname,movieEntity.var_url,movieEntity.filmdate,movieEntity.major))
            return var_result
        pass
    def updateTable(self,movieEntity:MovieEntity):
        pass

    def deleteTable(self,movieEntity:MovieEntity):
        pass
    def selectTable(self):
        var_movieEntity_list=[]
        with self.__pyMysqlUtil as var_cursor:
            var_sql='SELECT id,filmname,var_url,filmdate,major FROM t_movieinfo'
            var_result=var_cursor.execute(var_sql)
            print('查询到的记录数为：'.format(var_result))
            var_dict_list=var_cursor.fetchall()
            for element in var_dict_list:
                var_MovieEntity = MovieEntity(**element)
                var_movieEntity_list.append(var_MovieEntity)
                pass
        return var_movieEntity_list
    pass
